import junit.framework.TestCase;
import java.util.ArrayList;

/**
 * JUnit testing the methods in the class "Node.java".
 * @author Mattias Hinnerson
 */

public class TestNode extends TestCase {
	
	private Position pos1 = new Position(1,1);
	private Node node1 = new Node(pos1);
	private ArrayList<Position> theNeighbors = new ArrayList<Position>();
	private ArrayList<Position> movable = new ArrayList<Position>();
	private Network net = new Network();
	
	/**
	 * Test that the method returns the correct neighbors from the position 
	 * (x:1,y:1) and then the correct positions from the position (x:0,Y:0).
	 */
	public void testGetNeighbours() {

		Position posN = new Position(1,0);
		// checks North
		theNeighbors = node1.getNeighbours();
		pos1 = theNeighbors.get(0);
		assertEquals(pos1,posN);
		// Checks northwest
		Position posNW = new Position(0,0);
		pos1 = theNeighbors.get(1);
		assertEquals(pos1,posNW);
		// checks west
		Position posW = new Position(0,1);
		pos1 = theNeighbors.get(2);
		assertEquals(pos1,posW);
		// checks southWest
		Position posSW = new Position(0,2);
		pos1 = theNeighbors.get(3);
		assertEquals(pos1,posSW);
		// checks South
		Position posS = new Position(1,2);
		pos1 = theNeighbors.get(4);
		assertEquals(pos1,posS);
		// checks Southeast
		Position posSE = new Position(2,2);
		pos1 = theNeighbors.get(5);
		assertEquals(pos1,posSE);
		// checks east
		Position posE = new Position(2,1);
		pos1 = theNeighbors.get(6);
		assertEquals(pos1,posE);
		// Checks northEast
		Position posNE = new Position(2,0);
		pos1 = theNeighbors.get(7);
		assertEquals(pos1,posNE);
		
		// testing the node position (x:0,y:0): here the getNeighbours should 
		// give back totally 3 positions,S,SE and E.
		
		Position pos2 = new Position(0,0);
		Node node2 = new Node(pos2);
		
		//south.
		movable = node2.getNeighbours();
		assertEquals(movable.size(),3);
		Position posSouth = new Position(0,1);
		pos2 = movable.get(0);
		assertEquals(pos2,posSouth);
		
		//southEast.
		Position posSouthEast = new Position(1,1);
		pos2 = movable.get(1);
		assertEquals(pos2,posSouthEast);
		
		//East.
		Position posEast = new Position(1,0);
		pos2 = movable.get(2);
		assertEquals(pos2,posEast);
		
	}	
	/**
	 * Testing that it works to create one event and that it adds itself in
	 * networks eventList.
	 */
	public void testGenerateEvent() {
		
		while(net.EventList.isEmpty()){
		node1.generateEvent(net);
		}
		assertEquals(1,net.EventList.size());
	}

	/**
	 * Testing the method sendQuery works and it adds itself in networks 
	 * queryList. This test requires that networks QueryList is public.
	 */
	public void testSendQuery() {
		
		while(net.EventList.isEmpty()){
		node1.generateEvent(net);
		}
		node1.sendQuery(net);
		assertEquals(1,net.QueryList.size());
	}
}